using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;

namespace UniAspect.ContainerOverride
{
    public class ContainerOverridePolicy : IContainerOverridePolicy
    {
        public IUnityContainer Override { get; private set; }

        public ContainerOverridePolicy()
        {
            Override = null;
        }

        public ContainerOverridePolicy(IUnityContainer overrideContainer)
        {
            Guard.ArgumentNotNull(overrideContainer, "overrideContainer");

            Override = overrideContainer;
        }

        public object Resolve(NamedTypeBuildKey key)
        {
            return Override.Resolve(key.Type, key.Name);
        }
    }
}